{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<table style=\"float:left; border:none\">\n",
    "   <tr style=\"border:none; background-color: #ffffff\">\n",
    "       <td style=\"border:none\">\n",
    "           <a href=\"http://bokeh.pydata.org/\">     \n",
    "           <img \n",
    "               src=\"assets/bokeh-transparent.png\" \n",
    "               style=\"width:50px\"\n",
    "           >\n",
    "           </a>    \n",
    "       </td>\n",
    "       <td style=\"border:none\">\n",
    "           <h1>Bokeh 教程</h1>\n",
    "       </td>\n",
    "   </tr>\n",
    "</table>\n",
    "\n",
    "<div style=\"float:right;\"><h2>04. 数据源和数据转换</h2></div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from bokeh.io import output_notebook, show\n",
    "from bokeh.plotting import figure"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "    <div class=\"bk-root\">\n",
       "        <a href=\"https://bokeh.pydata.org\" target=\"_blank\" class=\"bk-logo bk-logo-small bk-logo-notebook\"></a>\n",
       "        <span id=\"56362abf-d7d0-4fcc-a97a-9e51ff2aab18\">Loading BokehJS ...</span>\n",
       "    </div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "\n",
       "(function(root) {\n",
       "  function now() {\n",
       "    return new Date();\n",
       "  }\n",
       "\n",
       "  var force = true;\n",
       "\n",
       "  if (typeof (root._bokeh_onload_callbacks) === \"undefined\" || force === true) {\n",
       "    root._bokeh_onload_callbacks = [];\n",
       "    root._bokeh_is_loading = undefined;\n",
       "  }\n",
       "\n",
       "  var JS_MIME_TYPE = 'application/javascript';\n",
       "  var HTML_MIME_TYPE = 'text/html';\n",
       "  var EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n",
       "  var CLASS_NAME = 'output_bokeh rendered_html';\n",
       "\n",
       "  /**\n",
       "   * Render data to the DOM node\n",
       "   */\n",
       "  function render(props, node) {\n",
       "    var script = document.createElement(\"script\");\n",
       "    node.appendChild(script);\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when an output is cleared or removed\n",
       "   */\n",
       "  function handleClearOutput(event, handle) {\n",
       "    var cell = handle.cell;\n",
       "\n",
       "    var id = cell.output_area._bokeh_element_id;\n",
       "    var server_id = cell.output_area._bokeh_server_id;\n",
       "    // Clean up Bokeh references\n",
       "    if (id !== undefined) {\n",
       "      Bokeh.index[id].model.document.clear();\n",
       "      delete Bokeh.index[id];\n",
       "    }\n",
       "\n",
       "    if (server_id !== undefined) {\n",
       "      // Clean up Bokeh references\n",
       "      var cmd = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n",
       "      cell.notebook.kernel.execute(cmd, {\n",
       "        iopub: {\n",
       "          output: function(msg) {\n",
       "            var element_id = msg.content.text.trim();\n",
       "            Bokeh.index[element_id].model.document.clear();\n",
       "            delete Bokeh.index[element_id];\n",
       "          }\n",
       "        }\n",
       "      });\n",
       "      // Destroy server and session\n",
       "      var cmd = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n",
       "      cell.notebook.kernel.execute(cmd);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when a new output is added\n",
       "   */\n",
       "  function handleAddOutput(event, handle) {\n",
       "    var output_area = handle.output_area;\n",
       "    var output = handle.output;\n",
       "\n",
       "    // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n",
       "    if ((output.output_type != \"display_data\") || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n",
       "      return\n",
       "    }\n",
       "\n",
       "    var toinsert = output_area.element.find(`.${CLASS_NAME.split(' ')[0]}`);\n",
       "\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n",
       "      toinsert[0].firstChild.textContent = output.data[JS_MIME_TYPE];\n",
       "      // store reference to embed id on output_area\n",
       "      output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n",
       "    }\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n",
       "      var bk_div = document.createElement(\"div\");\n",
       "      bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n",
       "      var script_attrs = bk_div.children[0].attributes;\n",
       "      for (var i = 0; i < script_attrs.length; i++) {\n",
       "        toinsert[0].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n",
       "      }\n",
       "      // store reference to server id on output_area\n",
       "      output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n",
       "    }\n",
       "  }\n",
       "\n",
       "  function register_renderer(events, OutputArea) {\n",
       "\n",
       "    function append_mime(data, metadata, element) {\n",
       "      // create a DOM node to render to\n",
       "      var toinsert = this.create_output_subarea(\n",
       "        metadata,\n",
       "        CLASS_NAME,\n",
       "        EXEC_MIME_TYPE\n",
       "      );\n",
       "      this.keyboard_manager.register_events(toinsert);\n",
       "      // Render to node\n",
       "      var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n",
       "      render(props, toinsert[0]);\n",
       "      element.append(toinsert);\n",
       "      return toinsert\n",
       "    }\n",
       "\n",
       "    /* Handle when an output is cleared or removed */\n",
       "    events.on('clear_output.CodeCell', handleClearOutput);\n",
       "    events.on('delete.Cell', handleClearOutput);\n",
       "\n",
       "    /* Handle when a new output is added */\n",
       "    events.on('output_added.OutputArea', handleAddOutput);\n",
       "\n",
       "    /**\n",
       "     * Register the mime type and append_mime function with output_area\n",
       "     */\n",
       "    OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n",
       "      /* Is output safe? */\n",
       "      safe: true,\n",
       "      /* Index of renderer in `output_area.display_order` */\n",
       "      index: 0\n",
       "    });\n",
       "  }\n",
       "\n",
       "  // register the mime type if in Jupyter Notebook environment and previously unregistered\n",
       "  if (root.Jupyter !== undefined) {\n",
       "    var events = require('base/js/events');\n",
       "    var OutputArea = require('notebook/js/outputarea').OutputArea;\n",
       "\n",
       "    if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n",
       "      register_renderer(events, OutputArea);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  \n",
       "  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n",
       "    root._bokeh_timeout = Date.now() + 5000;\n",
       "    root._bokeh_failed_load = false;\n",
       "  }\n",
       "\n",
       "  var NB_LOAD_WARNING = {'data': {'text/html':\n",
       "     \"<div style='background-color: #fdd'>\\n\"+\n",
       "     \"<p>\\n\"+\n",
       "     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n",
       "     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n",
       "     \"</p>\\n\"+\n",
       "     \"<ul>\\n\"+\n",
       "     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n",
       "     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n",
       "     \"</ul>\\n\"+\n",
       "     \"<code>\\n\"+\n",
       "     \"from bokeh.resources import INLINE\\n\"+\n",
       "     \"output_notebook(resources=INLINE)\\n\"+\n",
       "     \"</code>\\n\"+\n",
       "     \"</div>\"}};\n",
       "\n",
       "  function display_loaded() {\n",
       "    var el = document.getElementById(\"56362abf-d7d0-4fcc-a97a-9e51ff2aab18\");\n",
       "    if (el != null) {\n",
       "      el.textContent = \"BokehJS is loading...\";\n",
       "    }\n",
       "    if (root.Bokeh !== undefined) {\n",
       "      if (el != null) {\n",
       "        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n",
       "      }\n",
       "    } else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(display_loaded, 100)\n",
       "    }\n",
       "  }\n",
       "\n",
       "\n",
       "  function run_callbacks() {\n",
       "    try {\n",
       "      root._bokeh_onload_callbacks.forEach(function(callback) { callback() });\n",
       "    }\n",
       "    finally {\n",
       "      delete root._bokeh_onload_callbacks\n",
       "    }\n",
       "    console.info(\"Bokeh: all callbacks have finished\");\n",
       "  }\n",
       "\n",
       "  function load_libs(js_urls, callback) {\n",
       "    root._bokeh_onload_callbacks.push(callback);\n",
       "    if (root._bokeh_is_loading > 0) {\n",
       "      console.log(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n",
       "      return null;\n",
       "    }\n",
       "    if (js_urls == null || js_urls.length === 0) {\n",
       "      run_callbacks();\n",
       "      return null;\n",
       "    }\n",
       "    console.log(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n",
       "    root._bokeh_is_loading = js_urls.length;\n",
       "    for (var i = 0; i < js_urls.length; i++) {\n",
       "      var url = js_urls[i];\n",
       "      var s = document.createElement('script');\n",
       "      s.src = url;\n",
       "      s.async = false;\n",
       "      s.onreadystatechange = s.onload = function() {\n",
       "        root._bokeh_is_loading--;\n",
       "        if (root._bokeh_is_loading === 0) {\n",
       "          console.log(\"Bokeh: all BokehJS libraries loaded\");\n",
       "          run_callbacks()\n",
       "        }\n",
       "      };\n",
       "      s.onerror = function() {\n",
       "        console.warn(\"failed to load library \" + url);\n",
       "      };\n",
       "      console.log(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
       "      document.getElementsByTagName(\"head\")[0].appendChild(s);\n",
       "    }\n",
       "  };var element = document.getElementById(\"56362abf-d7d0-4fcc-a97a-9e51ff2aab18\");\n",
       "  if (element == null) {\n",
       "    console.log(\"Bokeh: ERROR: autoload.js configured with elementid '56362abf-d7d0-4fcc-a97a-9e51ff2aab18' but no matching script tag was found. \")\n",
       "    return false;\n",
       "  }\n",
       "\n",
       "  var js_urls = [\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.10.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.10.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.10.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-gl-0.12.10.min.js\"];\n",
       "\n",
       "  var inline_js = [\n",
       "    function(Bokeh) {\n",
       "      Bokeh.set_log_level(\"info\");\n",
       "    },\n",
       "    \n",
       "    function(Bokeh) {\n",
       "      \n",
       "    },\n",
       "    function(Bokeh) {\n",
       "      console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-0.12.10.min.css\");\n",
       "      Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.10.min.css\");\n",
       "      console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.10.min.css\");\n",
       "      Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.10.min.css\");\n",
       "      console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.10.min.css\");\n",
       "      Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.10.min.css\");\n",
       "    }\n",
       "  ];\n",
       "\n",
       "  function run_inline_js() {\n",
       "    \n",
       "    if ((root.Bokeh !== undefined) || (force === true)) {\n",
       "      for (var i = 0; i < inline_js.length; i++) {\n",
       "        inline_js[i].call(root, root.Bokeh);\n",
       "      }if (force === true) {\n",
       "        display_loaded();\n",
       "      }} else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(run_inline_js, 100);\n",
       "    } else if (!root._bokeh_failed_load) {\n",
       "      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n",
       "      root._bokeh_failed_load = true;\n",
       "    } else if (force !== true) {\n",
       "      var cell = $(document.getElementById(\"56362abf-d7d0-4fcc-a97a-9e51ff2aab18\")).parents('.cell').data().cell;\n",
       "      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n",
       "    }\n",
       "\n",
       "  }\n",
       "\n",
       "  if (root._bokeh_is_loading === 0) {\n",
       "    console.log(\"Bokeh: BokehJS loaded, going straight to plotting\");\n",
       "    run_inline_js();\n",
       "  } else {\n",
       "    load_libs(js_urls, function() {\n",
       "      console.log(\"Bokeh: BokehJS plotting callback run at\", now());\n",
       "      run_inline_js();\n",
       "    });\n",
       "  }\n",
       "}(window));"
      ],
      "application/vnd.bokehjs_load.v0+json": "\n(function(root) {\n  function now() {\n    return new Date();\n  }\n\n  var force = true;\n\n  if (typeof (root._bokeh_onload_callbacks) === \"undefined\" || force === true) {\n    root._bokeh_onload_callbacks = [];\n    root._bokeh_is_loading = undefined;\n  }\n\n  \n\n  \n  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n    root._bokeh_timeout = Date.now() + 5000;\n    root._bokeh_failed_load = false;\n  }\n\n  var NB_LOAD_WARNING = {'data': {'text/html':\n     \"<div style='background-color: #fdd'>\\n\"+\n     \"<p>\\n\"+\n     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n     \"</p>\\n\"+\n     \"<ul>\\n\"+\n     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n     \"</ul>\\n\"+\n     \"<code>\\n\"+\n     \"from bokeh.resources import INLINE\\n\"+\n     \"output_notebook(resources=INLINE)\\n\"+\n     \"</code>\\n\"+\n     \"</div>\"}};\n\n  function display_loaded() {\n    var el = document.getElementById(\"56362abf-d7d0-4fcc-a97a-9e51ff2aab18\");\n    if (el != null) {\n      el.textContent = \"BokehJS is loading...\";\n    }\n    if (root.Bokeh !== undefined) {\n      if (el != null) {\n        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n      }\n    } else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(display_loaded, 100)\n    }\n  }\n\n\n  function run_callbacks() {\n    try {\n      root._bokeh_onload_callbacks.forEach(function(callback) { callback() });\n    }\n    finally {\n      delete root._bokeh_onload_callbacks\n    }\n    console.info(\"Bokeh: all callbacks have finished\");\n  }\n\n  function load_libs(js_urls, callback) {\n    root._bokeh_onload_callbacks.push(callback);\n    if (root._bokeh_is_loading > 0) {\n      console.log(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n      return null;\n    }\n    if (js_urls == null || js_urls.length === 0) {\n      run_callbacks();\n      return null;\n    }\n    console.log(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n    root._bokeh_is_loading = js_urls.length;\n    for (var i = 0; i < js_urls.length; i++) {\n      var url = js_urls[i];\n      var s = document.createElement('script');\n      s.src = url;\n      s.async = false;\n      s.onreadystatechange = s.onload = function() {\n        root._bokeh_is_loading--;\n        if (root._bokeh_is_loading === 0) {\n          console.log(\"Bokeh: all BokehJS libraries loaded\");\n          run_callbacks()\n        }\n      };\n      s.onerror = function() {\n        console.warn(\"failed to load library \" + url);\n      };\n      console.log(\"Bokeh: injecting script tag for BokehJS library: \", url);\n      document.getElementsByTagName(\"head\")[0].appendChild(s);\n    }\n  };var element = document.getElementById(\"56362abf-d7d0-4fcc-a97a-9e51ff2aab18\");\n  if (element == null) {\n    console.log(\"Bokeh: ERROR: autoload.js configured with elementid '56362abf-d7d0-4fcc-a97a-9e51ff2aab18' but no matching script tag was found. \")\n    return false;\n  }\n\n  var js_urls = [\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.10.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.10.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.10.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-gl-0.12.10.min.js\"];\n\n  var inline_js = [\n    function(Bokeh) {\n      Bokeh.set_log_level(\"info\");\n    },\n    \n    function(Bokeh) {\n      \n    },\n    function(Bokeh) {\n      console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-0.12.10.min.css\");\n      Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.10.min.css\");\n      console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.10.min.css\");\n      Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.10.min.css\");\n      console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.10.min.css\");\n      Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.10.min.css\");\n    }\n  ];\n\n  function run_inline_js() {\n    \n    if ((root.Bokeh !== undefined) || (force === true)) {\n      for (var i = 0; i < inline_js.length; i++) {\n        inline_js[i].call(root, root.Bokeh);\n      }if (force === true) {\n        display_loaded();\n      }} else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(run_inline_js, 100);\n    } else if (!root._bokeh_failed_load) {\n      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n      root._bokeh_failed_load = true;\n    } else if (force !== true) {\n      var cell = $(document.getElementById(\"56362abf-d7d0-4fcc-a97a-9e51ff2aab18\")).parents('.cell').data().cell;\n      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n    }\n\n  }\n\n  if (root._bokeh_is_loading === 0) {\n    console.log(\"Bokeh: BokehJS loaded, going straight to plotting\");\n    run_inline_js();\n  } else {\n    load_libs(js_urls, function() {\n      console.log(\"Bokeh: BokehJS plotting callback run at\", now());\n      run_inline_js();\n    });\n  }\n}(window));"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "output_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 概要\n",
    "\n",
    "我们已经看到Bokeh怎么能够很好地与Python列表、NumPy数组、Pandas序列一起工作。在底层，这些输入数据被转换为Bokeh的`ColumnDataSource`类型。这个数据类型是Bokeh使用的核心数据源对象。虽然Bokeh经常通过透明的方式创建该类型对象，但有些时候也需要通过显式的方式创建。\n",
    "\n",
    "下一节，我们会看到hover tooltips，computed transforms 和 CustomJS interactions 等使用`ColumnDataSource`的功能，所以，现在我们快速的瞄一眼。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 通过 Python Dicts 创建\n",
    "\n",
    "从 `bokeh.models` 导入 `ColumnDataSource`："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from bokeh.models import ColumnDataSource"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`ColumnDataSource`是从列名（字符串）到值序列的映射。下面是一个简单的例子。映射是通过传入Python `dict`建立的，其字符串键作为列名，对应的Python list作为值序列。该值序列也可以是NumPy数组，或Pandas序列。\n",
    "\n",
    "***注意：`ColumnDataSource` 中所有的列必须等长。***\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "source = ColumnDataSource(data={\n",
    "    'x' : [1, 2, 3, 4, 5],\n",
    "    'y' : [3, 7, 8, 5, 1],\n",
    "})"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "到目前，我们已经通过直接传入文本列表或数组数据的方式调用函数，如`p.circle`。当我们这样做时，Bokeh会自动帮我们创建一个 `ColumnDataSource`。但我们也可以显式地把 `ColumnDataSource` 作为 `source` 参数传入glyph函数。当我们这样做时，如果我们想要给一个属性（如`\"x\"` 或 `\"y\"` 或 `\"fill_color\"`）指定一个值序列，我们传入对应的***列名***："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<div class=\"bk-root\">\n",
       "    <div class=\"bk-plotdiv\" id=\"18e95852-8087-4263-af13-44d21db9d94a\"></div>\n",
       "</div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    var docs_json = {\"491b329c-8660-4446-8468-bf64e02f4259\":{\"roots\":{\"references\":[{\"attributes\":{\"callback\":null},\"id\":\"09b4debc-f282-4ac4-af1a-de672d15f3fc\",\"type\":\"DataRange1d\"},{\"attributes\":{\"plot\":null,\"text\":\"\"},\"id\":\"b7ced955-62cd-4e34-a237-7f9e5fc1c120\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"0848b58f-3433-4c21-8869-0d233dd504d9\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"size\":{\"units\":\"screen\",\"value\":20},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"c578f49a-304e-4b2f-a525-9b463096125c\",\"type\":\"Circle\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":{\"value\":0.5},\"fill_color\":{\"value\":\"lightgrey\"},\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":{\"value\":1.0},\"line_color\":{\"value\":\"black\"},\"line_dash\":[4,4],\"line_width\":{\"value\":2},\"plot\":null,\"render_mode\":\"css\",\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"f087b887-2eac-4f07-86ae-afd327794af5\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"038ae7e3-29cf-444d-b87c-cc43990f5e7d\",\"type\":\"LinearScale\"},{\"attributes\":{\"overlay\":{\"id\":\"f087b887-2eac-4f07-86ae-afd327794af5\",\"type\":\"BoxAnnotation\"}},\"id\":\"74d9335f-9075-4fb6-b52f-17dff47a9c84\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"9f7d058e-4fd0-4f20-9a5d-744c4c45cdd9\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"3a5e50b7-8e25-452a-9709-1711ad752431\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"957d8a07-dd18-47f1-9616-f7e1502a8083\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"7d1ef6bb-f86b-470a-9790-2ea5b5755a84\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"831e5032-53cc-41f1-b5f0-df7015660864\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"formatter\":{\"id\":\"831e5032-53cc-41f1-b5f0-df7015660864\",\"type\":\"BasicTickFormatter\"},\"plot\":{\"id\":\"f61fe9ae-ec1c-40e6-b7cf-aadacafe9324\",\"subtype\":\"Figure\",\"type\":\"Plot\"},\"ticker\":{\"id\":\"b1de0a60-e8ed-4d4d-8e54-12f7c8cb6066\",\"type\":\"BasicTicker\"}},\"id\":\"a5219319-e0dc-4efa-96d1-93d5f7bf85ff\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"d2abefeb-ee80-4bdb-95bf-f592af7d0f40\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"b1de0a60-e8ed-4d4d-8e54-12f7c8cb6066\",\"type\":\"BasicTicker\"},{\"attributes\":{\"source\":{\"id\":\"c39a0cca-b129-4e5f-b898-c035c795f27b\",\"type\":\"ColumnDataSource\"}},\"id\":\"4dce5277-b5a9-4447-ad3a-80d723934921\",\"type\":\"CDSView\"},{\"attributes\":{\"plot\":{\"id\":\"f61fe9ae-ec1c-40e6-b7cf-aadacafe9324\",\"subtype\":\"Figure\",\"type\":\"Plot\"},\"ticker\":{\"id\":\"b1de0a60-e8ed-4d4d-8e54-12f7c8cb6066\",\"type\":\"BasicTicker\"}},\"id\":\"1361ebee-aca1-4d76-b332-4d905fab7350\",\"type\":\"Grid\"},{\"attributes\":{\"callback\":null,\"column_names\":[\"x\",\"y\"],\"data\":{\"x\":[1,2,3,4,5],\"y\":[3,7,8,5,1]}},\"id\":\"c39a0cca-b129-4e5f-b898-c035c795f27b\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"formatter\":{\"id\":\"3a5e50b7-8e25-452a-9709-1711ad752431\",\"type\":\"BasicTickFormatter\"},\"plot\":{\"id\":\"f61fe9ae-ec1c-40e6-b7cf-aadacafe9324\",\"subtype\":\"Figure\",\"type\":\"Plot\"},\"ticker\":{\"id\":\"35b080fb-6065-40cb-aaa2-891a3586f4a9\",\"type\":\"BasicTicker\"}},\"id\":\"e54a7133-53b6-4f65-9f0f-cdfd706566db\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"35b080fb-6065-40cb-aaa2-891a3586f4a9\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"c0953bb9-56aa-4bac-bfb1-66599adf3fc2\",\"type\":\"PanTool\"},{\"attributes\":{\"dimension\":1,\"plot\":{\"id\":\"f61fe9ae-ec1c-40e6-b7cf-aadacafe9324\",\"subtype\":\"Figure\",\"type\":\"Plot\"},\"ticker\":{\"id\":\"35b080fb-6065-40cb-aaa2-891a3586f4a9\",\"type\":\"BasicTicker\"}},\"id\":\"661b2ef2-828d-4e89-8c65-8908ec736166\",\"type\":\"Grid\"},{\"attributes\":{\"below\":[{\"id\":\"a5219319-e0dc-4efa-96d1-93d5f7bf85ff\",\"type\":\"LinearAxis\"}],\"left\":[{\"id\":\"e54a7133-53b6-4f65-9f0f-cdfd706566db\",\"type\":\"LinearAxis\"}],\"plot_height\":400,\"plot_width\":400,\"renderers\":[{\"id\":\"a5219319-e0dc-4efa-96d1-93d5f7bf85ff\",\"type\":\"LinearAxis\"},{\"id\":\"1361ebee-aca1-4d76-b332-4d905fab7350\",\"type\":\"Grid\"},{\"id\":\"e54a7133-53b6-4f65-9f0f-cdfd706566db\",\"type\":\"LinearAxis\"},{\"id\":\"661b2ef2-828d-4e89-8c65-8908ec736166\",\"type\":\"Grid\"},{\"id\":\"f087b887-2eac-4f07-86ae-afd327794af5\",\"type\":\"BoxAnnotation\"},{\"id\":\"b7e15208-9949-4f8a-b929-5d7afbd84e75\",\"type\":\"GlyphRenderer\"}],\"title\":{\"id\":\"b7ced955-62cd-4e34-a237-7f9e5fc1c120\",\"type\":\"Title\"},\"toolbar\":{\"id\":\"e972e0ea-5439-4302-8991-db9ee66ea36e\",\"type\":\"Toolbar\"},\"x_range\":{\"id\":\"54340c38-1d87-4912-b546-181a7fa319d1\",\"type\":\"DataRange1d\"},\"x_scale\":{\"id\":\"038ae7e3-29cf-444d-b87c-cc43990f5e7d\",\"type\":\"LinearScale\"},\"y_range\":{\"id\":\"09b4debc-f282-4ac4-af1a-de672d15f3fc\",\"type\":\"DataRange1d\"},\"y_scale\":{\"id\":\"9f7d058e-4fd0-4f20-9a5d-744c4c45cdd9\",\"type\":\"LinearScale\"}},\"id\":\"f61fe9ae-ec1c-40e6-b7cf-aadacafe9324\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"data_source\":{\"id\":\"c39a0cca-b129-4e5f-b898-c035c795f27b\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"c30288e7-2518-4949-a5e2-6848c5fdfa87\",\"type\":\"Circle\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"c578f49a-304e-4b2f-a525-9b463096125c\",\"type\":\"Circle\"},\"selection_glyph\":null,\"view\":{\"id\":\"4dce5277-b5a9-4447-ad3a-80d723934921\",\"type\":\"CDSView\"}},\"id\":\"b7e15208-9949-4f8a-b929-5d7afbd84e75\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"size\":{\"units\":\"screen\",\"value\":20},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"c30288e7-2518-4949-a5e2-6848c5fdfa87\",\"type\":\"Circle\"},{\"attributes\":{\"callback\":null},\"id\":\"54340c38-1d87-4912-b546-181a7fa319d1\",\"type\":\"DataRange1d\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"c0953bb9-56aa-4bac-bfb1-66599adf3fc2\",\"type\":\"PanTool\"},{\"id\":\"0848b58f-3433-4c21-8869-0d233dd504d9\",\"type\":\"WheelZoomTool\"},{\"id\":\"74d9335f-9075-4fb6-b52f-17dff47a9c84\",\"type\":\"BoxZoomTool\"},{\"id\":\"957d8a07-dd18-47f1-9616-f7e1502a8083\",\"type\":\"SaveTool\"},{\"id\":\"7d1ef6bb-f86b-470a-9790-2ea5b5755a84\",\"type\":\"ResetTool\"},{\"id\":\"d2abefeb-ee80-4bdb-95bf-f592af7d0f40\",\"type\":\"HelpTool\"}]},\"id\":\"e972e0ea-5439-4302-8991-db9ee66ea36e\",\"type\":\"Toolbar\"}],\"root_ids\":[\"f61fe9ae-ec1c-40e6-b7cf-aadacafe9324\"]},\"title\":\"Bokeh Application\",\"version\":\"0.12.10\"}};\n",
       "    var render_items = [{\"docid\":\"491b329c-8660-4446-8468-bf64e02f4259\",\"elementid\":\"18e95852-8087-4263-af13-44d21db9d94a\",\"modelid\":\"f61fe9ae-ec1c-40e6-b7cf-aadacafe9324\"}];\n",
       "\n",
       "    root.Bokeh.embed.embed_items(docs_json, render_items);\n",
       "  }\n",
       "\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        embed_document(root);\n",
       "        clearInterval(timer);\n",
       "      }\n",
       "      attempts++;\n",
       "      if (attempts > 100) {\n",
       "        console.log(\"Bokeh: ERROR: Unable to embed document because BokehJS library is missing\")\n",
       "        clearInterval(timer);\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "f61fe9ae-ec1c-40e6-b7cf-aadacafe9324"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "p = figure(plot_width=400, plot_height=400)\n",
    "p.circle('x', 'y', size=20, source=source)\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Exercise: create a column data source with NumPy arrays as column values and plot it\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 通过 Pandas DataFrames 创建\n",
    "\n",
    "通过Pandas Dataframe创建 `ColumnDataSource` 对象也很容易。只需要在创建 `ColumnDataSource` 的时候把Dataframe传入就行："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from bokeh.sampledata.iris import flowers as df\n",
    "\n",
    "source = ColumnDataSource(df)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "现在我们就可以使用这个对象绘制上例中的图了，把对应的列名传入glyph函数："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<div class=\"bk-root\">\n",
       "    <div class=\"bk-plotdiv\" id=\"05e0cd8a-1a16-4eb0-b9fa-9740fed15a9e\"></div>\n",
       "</div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    var docs_json = {\"a37fa3ed-5818-4cbf-a4a3-26e4913637fb\":{\"roots\":{\"references\":[{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"bf80bcc8-1af8-42a5-b181-16b99cfa1210\",\"type\":\"PanTool\"},{\"id\":\"be36ed3d-bdb9-4233-aa11-4992585b58a7\",\"type\":\"WheelZoomTool\"},{\"id\":\"c24c9acf-180d-427d-93e7-65560a70b295\",\"type\":\"BoxZoomTool\"},{\"id\":\"2659891f-a1b0-4696-bd71-773c764909ce\",\"type\":\"SaveTool\"},{\"id\":\"f6cd3eb1-269f-45aa-b520-e73b69193edd\",\"type\":\"ResetTool\"},{\"id\":\"b90f43b1-db30-48fd-bcaf-f9ba1639b0ce\",\"type\":\"HelpTool\"}]},\"id\":\"97036cae-4d2d-4b10-a750-940110130b17\",\"type\":\"Toolbar\"},{\"attributes\":{\"callback\":null},\"id\":\"62fd8927-de71-4110-ad6f-27c48dba010f\",\"type\":\"DataRange1d\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"x\":{\"field\":\"petal_length\"},\"y\":{\"field\":\"petal_width\"}},\"id\":\"f90d6ada-32ae-48c7-9b96-5498198133db\",\"type\":\"Circle\"},{\"attributes\":{},\"id\":\"2659891f-a1b0-4696-bd71-773c764909ce\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"13d73144-e02e-4088-82ee-55abfa061c9a\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"f6cd3eb1-269f-45aa-b520-e73b69193edd\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"eb2d49a5-1ab1-4953-b0dd-1d4daf1530e0\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"b90f43b1-db30-48fd-bcaf-f9ba1639b0ce\",\"type\":\"HelpTool\"},{\"attributes\":{\"plot\":{\"id\":\"0f56faa0-55f3-416c-a3c7-32a06b708962\",\"subtype\":\"Figure\",\"type\":\"Plot\"},\"ticker\":{\"id\":\"0e06b8f6-eb0e-410b-955e-46c4495a93f8\",\"type\":\"BasicTicker\"}},\"id\":\"3cbf59b9-87db-4de9-925d-96cbe4358cbc\",\"type\":\"Grid\"},{\"attributes\":{\"formatter\":{\"id\":\"c46bb2cb-38bc-4f3e-be3f-6eabc5378d63\",\"type\":\"BasicTickFormatter\"},\"plot\":{\"id\":\"0f56faa0-55f3-416c-a3c7-32a06b708962\",\"subtype\":\"Figure\",\"type\":\"Plot\"},\"ticker\":{\"id\":\"0e06b8f6-eb0e-410b-955e-46c4495a93f8\",\"type\":\"BasicTicker\"}},\"id\":\"16fbe6e4-30ce-4f99-86a0-927f51048842\",\"type\":\"LinearAxis\"},{\"attributes\":{\"plot\":null,\"text\":\"\"},\"id\":\"e7728527-9044-4ca5-9a5f-c737373b20c5\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"0e06b8f6-eb0e-410b-955e-46c4495a93f8\",\"type\":\"BasicTicker\"},{\"attributes\":{\"formatter\":{\"id\":\"51f6d278-c656-4718-84a2-dfe1a864a593\",\"type\":\"BasicTickFormatter\"},\"plot\":{\"id\":\"0f56faa0-55f3-416c-a3c7-32a06b708962\",\"subtype\":\"Figure\",\"type\":\"Plot\"},\"ticker\":{\"id\":\"9af5cf44-cda5-4f48-ae37-f7a8b413c1a5\",\"type\":\"BasicTicker\"}},\"id\":\"0fddb9b6-45d7-4fc7-b2d4-a3061c7cb6c3\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"9af5cf44-cda5-4f48-ae37-f7a8b413c1a5\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"c46bb2cb-38bc-4f3e-be3f-6eabc5378d63\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"dimension\":1,\"plot\":{\"id\":\"0f56faa0-55f3-416c-a3c7-32a06b708962\",\"subtype\":\"Figure\",\"type\":\"Plot\"},\"ticker\":{\"id\":\"9af5cf44-cda5-4f48-ae37-f7a8b413c1a5\",\"type\":\"BasicTicker\"}},\"id\":\"d1b31315-b19c-4d16-ba52-fb84fa2b02ed\",\"type\":\"Grid\"},{\"attributes\":{\"data_source\":{\"id\":\"2d70c300-7abf-450a-aa6b-8845ae5aa9b0\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"9bb3c4e0-1622-40bc-9c77-490f85d807b8\",\"type\":\"Circle\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"f90d6ada-32ae-48c7-9b96-5498198133db\",\"type\":\"Circle\"},\"selection_glyph\":null,\"view\":{\"id\":\"a4965883-6c09-4e2e-9764-4fade465fd3d\",\"type\":\"CDSView\"}},\"id\":\"414a68a2-7f68-476b-af0d-98e027d46644\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"x\":{\"field\":\"petal_length\"},\"y\":{\"field\":\"petal_width\"}},\"id\":\"9bb3c4e0-1622-40bc-9c77-490f85d807b8\",\"type\":\"Circle\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":{\"value\":0.5},\"fill_color\":{\"value\":\"lightgrey\"},\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":{\"value\":1.0},\"line_color\":{\"value\":\"black\"},\"line_dash\":[4,4],\"line_width\":{\"value\":2},\"plot\":null,\"render_mode\":\"css\",\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"e941d065-58e6-407c-9b95-b24e5a5c0223\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"51f6d278-c656-4718-84a2-dfe1a864a593\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"bf80bcc8-1af8-42a5-b181-16b99cfa1210\",\"type\":\"PanTool\"},{\"attributes\":{\"below\":[{\"id\":\"16fbe6e4-30ce-4f99-86a0-927f51048842\",\"type\":\"LinearAxis\"}],\"left\":[{\"id\":\"0fddb9b6-45d7-4fc7-b2d4-a3061c7cb6c3\",\"type\":\"LinearAxis\"}],\"plot_height\":400,\"plot_width\":400,\"renderers\":[{\"id\":\"16fbe6e4-30ce-4f99-86a0-927f51048842\",\"type\":\"LinearAxis\"},{\"id\":\"3cbf59b9-87db-4de9-925d-96cbe4358cbc\",\"type\":\"Grid\"},{\"id\":\"0fddb9b6-45d7-4fc7-b2d4-a3061c7cb6c3\",\"type\":\"LinearAxis\"},{\"id\":\"d1b31315-b19c-4d16-ba52-fb84fa2b02ed\",\"type\":\"Grid\"},{\"id\":\"e941d065-58e6-407c-9b95-b24e5a5c0223\",\"type\":\"BoxAnnotation\"},{\"id\":\"414a68a2-7f68-476b-af0d-98e027d46644\",\"type\":\"GlyphRenderer\"}],\"title\":{\"id\":\"e7728527-9044-4ca5-9a5f-c737373b20c5\",\"type\":\"Title\"},\"toolbar\":{\"id\":\"97036cae-4d2d-4b10-a750-940110130b17\",\"type\":\"Toolbar\"},\"x_range\":{\"id\":\"343688a2-8ea8-4fba-96f5-2014ce2c27ff\",\"type\":\"DataRange1d\"},\"x_scale\":{\"id\":\"13d73144-e02e-4088-82ee-55abfa061c9a\",\"type\":\"LinearScale\"},\"y_range\":{\"id\":\"62fd8927-de71-4110-ad6f-27c48dba010f\",\"type\":\"DataRange1d\"},\"y_scale\":{\"id\":\"eb2d49a5-1ab1-4953-b0dd-1d4daf1530e0\",\"type\":\"LinearScale\"}},\"id\":\"0f56faa0-55f3-416c-a3c7-32a06b708962\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"callback\":null,\"column_names\":[\"sepal_length\",\"sepal_width\",\"petal_length\",\"petal_width\",\"species\",\"index\"],\"data\":{\"index\":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149],\"petal_length\":{\"__ndarray__\":\"ZmZmZmZm9j9mZmZmZmb2P83MzMzMzPQ/AAAAAAAA+D9mZmZmZmb2PzMzMzMzM/s/ZmZmZmZm9j8AAAAAAAD4P2ZmZmZmZvY/AAAAAAAA+D8AAAAAAAD4P5qZmZmZmfk/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zAhAAAAAAAAACEDNzMzMzMwIQM3MzMzMzAhAzczMzMzMCECamZmZmZkFQJqZmZmZmQlAZmZmZmZmCkAAAAAAAAAIQAAAAAAAAARAAAAAAAAACEAzMzMzMzMLQAAAAAAAAAhA\",\"dtype\":\"float64\",\"shape\":[150]},\"species\":[\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"setosa\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"versicolor\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\",\"virginica\"]}},\"id\":\"2d70c300-7abf-450a-aa6b-8845ae5aa9b0\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"be36ed3d-bdb9-4233-aa11-4992585b58a7\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"source\":{\"id\":\"2d70c300-7abf-450a-aa6b-8845ae5aa9b0\",\"type\":\"ColumnDataSource\"}},\"id\":\"a4965883-6c09-4e2e-9764-4fade465fd3d\",\"type\":\"CDSView\"},{\"attributes\":{\"callback\":null},\"id\":\"343688a2-8ea8-4fba-96f5-2014ce2c27ff\",\"type\":\"DataRange1d\"},{\"attributes\":{\"overlay\":{\"id\":\"e941d065-58e6-407c-9b95-b24e5a5c0223\",\"type\":\"BoxAnnotation\"}},\"id\":\"c24c9acf-180d-427d-93e7-65560a70b295\",\"type\":\"BoxZoomTool\"}],\"root_ids\":[\"0f56faa0-55f3-416c-a3c7-32a06b708962\"]},\"title\":\"Bokeh Application\",\"version\":\"0.12.10\"}};\n",
       "    var render_items = [{\"docid\":\"a37fa3ed-5818-4cbf-a4a3-26e4913637fb\",\"elementid\":\"05e0cd8a-1a16-4eb0-b9fa-9740fed15a9e\",\"modelid\":\"0f56faa0-55f3-416c-a3c7-32a06b708962\"}];\n",
       "\n",
       "    root.Bokeh.embed.embed_items(docs_json, render_items);\n",
       "  }\n",
       "\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        embed_document(root);\n",
       "        clearInterval(timer);\n",
       "      }\n",
       "      attempts++;\n",
       "      if (attempts > 100) {\n",
       "        console.log(\"Bokeh: ERROR: Unable to embed document because BokehJS library is missing\")\n",
       "        clearInterval(timer);\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "0f56faa0-55f3-416c-a3c7-32a06b708962"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "p = figure(plot_width=400, plot_height=400)\n",
    "p.circle('petal_length', 'petal_width', source=source)\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Exercise: create a column data source with the autompg sample data frame and plot it\n",
    "\n",
    "from bokeh.sampledata.autompg import autompg_clean as df\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
